/*************************************************
* Title：TinyToolKit
* Author：Opportunity 
* Discribe：显示摄像机的拍摄视野范围，挂载摄像机上即可
* CreateTime：2020-06-15 15:18:38
* Version：1.0
* Modify Recoder：
*************************************************/

using UnityEngine;

namespace TinyToolKit
{
    [RequireComponent(typeof(Camera))]
    public class ShowCamFieldArea : MonoBehaviour
    {
        public bool showField = true;
        public Camera targetCam;
        public Color color = Color.green;

#if UNITY_EDITOR
        private void OnDrawGizmos()
        {
            if (showField == false) return;

            if (targetCam == null)
                targetCam = gameObject.GetComponent<Camera>();

            var tempColor = Gizmos.color;
            Gizmos.color = color;
            Gizmos.matrix = Matrix4x4.TRS(targetCam.transform.position, targetCam.transform.rotation, Vector3.one);
            Gizmos.DrawFrustum(Vector3.zero, targetCam.fieldOfView, targetCam.farClipPlane, targetCam.nearClipPlane, targetCam.aspect);
            Gizmos.color = tempColor;
        }
#endif
    }
}

